package framework.object;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class ResourceType {

    private String defaultExtension;

    private String[] otherExtensions;

    private static final Map<String, ResourceType> CACHE = Collections.synchronizedMap(new HashMap<String, ResourceType>());
    public static ResourceType determineResourceType(final String resourceName) {
        for (ResourceType type : CACHE.values()) {
            if (type.matchesExtension(resourceName)) {
                return type;
            }
        }
        return null;
    }

    public boolean matchesExtension(String resourceName) {
        if (resourceName != null) {

            if (resourceName.endsWith("." + defaultExtension)) {
                return true;
            }
            for (String extension : otherExtensions) {
                if (resourceName.endsWith("." + extension)) {
                    return true;
                }
            }
        }
        return false;
    }
}
